{include file="public/header" /}





<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.goods_class_index_class}</h3>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

    <div class="explanation" id="explanation">
        <div class="title" id="checkZoom">
            <h4 title="{$Think.lang.ds_explanation_tip}">{$Think.lang.ds_explanation}</h4>
            <span id="explanationZoom" title="{$Think.lang.ds_explanation_close}" class="arrow"></span>
        </div>
        <ul>
            <li>{$Think.lang.goods_class_edit_prompts_one}</li>
            <li>{$Think.lang.goods_class_edit_prompts_two}</li>
        </ul>
    </div>
    

    <form id="goods_class_form" name="goodsClassForm" enctype="multipart/form-data" method="post" action="{:url('Goodsclass/goods_class_edit')}" >
        <input type="hidden" name="gc_id" value="{$class_array.gc_id}" />
        <input type="hidden" name="gc_parent_id" id="gc_parent_id" value="{$class_array.gc_parent_id}" />
        <input type="hidden" name="old_type_id" value="{$class_array.type_id}">
        <table class="ds-default-table">
            <tbody>
                <tr class="noborder">
                    <td  class="required w80"><label class="gc_name validation" for="gc_name">{$Think.lang.goods_class_index_name}:</label></td>
                    <td class="vatop rowform"><input type="text" maxlength="20" value="{$class_array.gc_name}" name="gc_name" id="gc_name" class="txt"></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr>
                    <td class="required w80"><label for="parent_id">{$Think.lang.goods_class_add_sup_class}:</label></td>
                    <td class="vatop rowform"><select name="gc_parent_id" id="gc_parent_id">
                        <option value="{$class_array.gc_parent_id}">{$Think.lang.gc_parent_id_selected}</option>
                        {notempty name="parent_list"}
                        {foreach name="parent_list" item="v" key="k" }
                        <option {if $class_array.gc_parent_id == $v.gc_id}selected='selected'{/if} value="{$v.gc_id}">{$v.gc_name}</option>
                        {/foreach}
                        {/notempty}
                    </select></td>
                    <td class="vatop tips"><span style="color:#ff0000">{$Think.lang.goods_class_edit_sup_class_notice}</span> {$Think.lang.goods_class_add_sup_class_notice}</td>
                </tr>


                {if empty($class_array.gc_images)}
                 <tr class="noborder"  id="video_type">
                     <td class="required w120">图片:</td>
                     <td class="vatop rowform">
                         <div class="dssc-goods-default-pic">
                             <div class="goodspic-uplaod">
                                 <span></span>
                                 <input type="hidden" name="videos" id="video_name">

                                 <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Goodproject/ajax_videos')}">
                                 </span>
                                 <p class="hint"></p>
                             </div>
                         </div>
                         <div id="dataLoading" class="wp_data_loading">
                             <div class="data_loading"></div>
                         </div>
                         <div id="demo">
                         </div>
                     </td>
                 </tr>
            {else if/}
                 <tr class="noborder"  id="video_type">
                     <td class="required w120">图片:</td>
                     <td class="vatop rowform">
                         <div class="dssc-goods-default-pic">
                             <div class="goodspic-uplaod">
                                 <span></span>
                                 <img width="300px" height="200px" src="{$http_name}/{$class_array.gc_images}" />
                                 <input type="hidden" name="videos" id="video_name">

                                 <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Goodproject/ajax_videos')}">
                                 </span>
                                 <p class="hint"></p>
                             </div>
                         </div>
                         <div id="dataLoading" class="wp_data_loading">
                             <div class="data_loading"></div>
                         </div>
                         <div id="demo">
                         </div>
                     </td>
                 </tr>
            {/if}


 <!--                <tr class="noborder"  id="video_type">
                     <td class="required w120">图片:</td>
                     <td class="vatop rowform">
                         <div class="dssc-goods-default-pic">
                             <div class="goodspic-uplaod">
                                 <span></span>
                                 <input type="hidden" name="videos" id="video_name">

                                 <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Goodproject/ajax_videos')}">
                                 </span>
                                 <p class="hint"></p>
                             </div>
                         </div>
                         <div id="dataLoading" class="wp_data_loading">
                             <div class="data_loading"></div>
                         </div>
                         <div id="demo">
                         </div>
                     </td>
                 </tr> -->
<!--                 <tr>
                    <td class="required w80"><label for="pic">{$Think.lang.goods_class_pic}:</label></td>
                    <td class="vatop rowform">
                        {notempty name="$class_array.pic"}
                        <span class="type-file-show"><img class="show_image" src="{$Think.ADMIN_SITE_ROOT}/images/preview.png">
                            <div class="type-file-preview"><img src="{$class_array.pic}"></div>
                        </span>
                        {/notempty}
                        <span class="type-file-box">
                            <input type='text' name='textfield' id='textfield1' class='type-file-text' />
                            <input type='button' name='button' id='button1' value='' class='type-file-button' />
                            <input name="pic" type="file" class="type-file-file" id="pic" size="30" hidefocus="true" ds_type="change_pic">
                        </span>
                    </td>
                    <td class="vatop tips">{$Think.lang.goods_class_pic_tips}</td>
                </tr> -->
               <!-- <tr>
                    <td colspan="2" class="required"><label>{$Think.lang.gc_virtual}:</label>
                        <span>
                            <label for="t_gc_virtual"><input id="t_gc_virtual" type="checkbox" class="checkbox" checked="checked" value="1" name="t_gc_virtual">{$Think.lang.goods_class_edit_related_to_subclass}</label>
                        </span>
                    </td>
                </tr>
                <tr class="noborder">
                    <td class="vatop rowform"><label><input type="checkbox" name="gc_virtual" id="gc_virtual" value="1" {if $class_array.gc_virtual == 1}checked{/if}>{$Think.lang.ds_allow}</label></td>
                    <td class="vatop tips">{$Think.lang.gc_virtual_tips}</td>
                </tr>-->
                <!-- <tr>
                    <td class="required w80"><label class="validation">{$Think.lang.commis_rate}:</label>
                        <span>
                            <label for="t_commis_rate"><input id="t_commis_rate" class="checkbox" type="checkbox" checked="checked" value="1" name="t_commis_rate">{$Think.lang.goods_class_edit_related_to_subclass}</label>
                        </span></td>
                    <td class="vatop rowform"><input id="commis_rate" class="w60" type="text" value="{$class_array.commis_rate}" name="commis_rate">
                        % </td>
                    <td class="vatop tips">{$Think.lang.commis_rate_tips}</td>
                </tr> -->
                <tr>
                    <td colspan="2" class="required"><label class="validation">{$Think.lang.goods_class_add_type}:</label>
                        <span>
                            <label for="t_associated">
                                <input class="checkbox" type="checkbox" name="t_associated" value="1" checked="checked" id="t_associated" />
                                {$Think.lang.goods_class_edit_related_to_subclass}</label>
                        </span>
                    </td>
                </tr>
                <tr class="noborder">
                    <td colspan="2" id="gcategory">
                        <select class="class-select">
                            <option value="0">{$Think.lang.ds_please_choose}...</option>
                            {notempty name="gc_list"}
                            {foreach name="gc_list" item="v" key="k" }
                            {if $v.gc_parent_id == 0}
                            <option value="{$v.gc_id}">{$v.gc_name}</option>
                            {/if}
                            {/foreach}
                            {/notempty}
                        </select>
                        {$Think.lang.ds_quickly_targeted}
                    </td>
                </tr>
                <tr class="noborder">
                    <td class="vatop rowform"><input type="hidden" name="t_name" id="t_name" value="{$class_array.type_name}" />
                        <input type="hidden" name="t_sign" id="t_sign" value="" />
                        <div id="type_div" class="goods-sort-type">
                            <div class="container">
                                <dl>
                                    <dd>
                                        <input type="radio" name="t_id" value="0" {if $class_array.type_id}checked="checked"{/if} />{$Think.lang.goods_class_null_type}
                                    </dd>
                                </dl>
                                {notempty name="type_list"}
                                {foreach name="type_list" item="val" key="k" }
                                {notempty name="$val.type"}
                                <dl>
                                    <dt id="type_dt_{$k}">{$val.name}</dt>
                                     {foreach name="$val.type" item="v" }
                                    <dd><input type="radio" class="radio" name="t_id" value="{$v.type_id}" {if $class_array.type_id == $v.type_id}checked="checked"{/if} /><span>{$v.type_name}</span></dd>
                                    {/foreach}
                                </dl>
                                {/notempty}
                                {/foreach}
                                {/notempty}
                            </div>
                        </div></td>
                    <td class="vatop tips">{$Think.lang.goods_class_add_type_desc_one}<a onclick="window.parent.openItem('index,type,goods')" href="JavaScript:void(0);">{$Think.lang.ds_type}</a>{$Think.lang.goods_class_add_type_desc_two}</td>
                </tr>
                <tr>
                    <td colspan="2" class="required"><label for="gc_sort">{$Think.lang.ds_sort}:</label>
<input style="margin-left: 107px;" type="text" value="{if $class_array.gc_sort == ''}0{else/}{$class_array.gc_sort}{/if}" name="gc_sort" id="gc_sort" class="txt">
                    </td>
                </tr>
                
                <tr class="noborder">
                    <td class="required">是否显示首页: </td>
                    <td class="vatop rowform onoff">
                        <label for="brand_recommend1" class="cb-enable {if $class_array.status == '1'}selected{/if}" title="{$Think.lang.ds_yes}"><span>显示</span></label>
                        <label for="brand_recommend0" class="cb-disable {if $class_array.status == '0'}selected{/if}" title="{$Think.lang.ds_no}"><span>不显示</span></label>
                        <input id="brand_recommend1" name="status" {if $class_array.status == '1'}checked="checked"{/if} value="1" type="radio">
                        <input id="brand_recommend0" name="status" {if $class_array.status == '0'}checked="checked"{/if} value="0" type="radio"></td>
                </tr>
<!--                 <tr class="noborder">
                    <td class="vatop rowform"><input type="text" value="{if $class_array.gc_sort == ''}0{else/}{$class_array.gc_sort}{/if}" name="gc_sort" id="gc_sort" class="txt"></td>
                    <td class="vatop tips">{$Think.lang.goods_class_add_update_sort}</td>
                </tr> -->
            </tbody>
            <tfoot>
                <tr class="tfoot">
                    <td colspan="15" ><input class="btn" type="submit" value="{$Think.lang.ds_submit}" style="line-height: 30px;"/></td>
                </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script> 
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script> 
<script>
    $(document).ready(function(){
        $('#goods_class_form').validate({
            errorPlacement: function(error, element) {
                error.appendTo(element.parent().parent().prev().find('td:first'));
            },
            rules: {
                gc_name: {
                    required: true,
                    remote: {
                        url: "{:url('Goodsclass/ajax',['branch'=>'check_class_name'])}",
                        type: 'get',
                        data: {
                            gc_name: function() {
                                return $('#gc_name').val();
                            },
                            gc_parent_id: function() {
                                return $('#gc_parent_id').val();
                            },
                            gc_id: '{$class_array.gc_id}'
                        }
                    }
                },
                // commis_rate: {
                //     required: true,
                //     max: 100,
                //     min: 0,
                //     digits: true
                // },
                gc_sort: {
                    number: true
                }
            },
            messages: {
                gc_name: {
                    required: '{$Think.lang.goods_class_add_name_null}',
                    remote: '{$Think.lang.goods_class_add_name_exists}'
                },
                // commis_rate: {
                //     required: '{$Think.lang.goods_class_add_commis_rate_error}',
                //     max: '{$Think.lang.goods_class_add_commis_rate_error}',
                //     min: '{$Think.lang.goods_class_add_commis_rate_error}',
                //     digits: '{$Think.lang.goods_class_add_commis_rate_error}'
                // },
                gc_sort: {
                    number: '{$Think.lang.goods_class_add_sort_int}'
                }
            }
        });

     $('form').submit(function(){
        var res = $(this).valid();
        if(res){
            var url = $('form').attr('action');
            // alert(url);return false;
            $.ajax({
                type: "POST",
                url: url,
                data: $('form').serialize(),
                error: function (request) {
                    alert("Connection error");
                },
                success: function (result) {
                    //  alter(result);return false;
                    if (result.code == 0) {
                        layer.msg(result.msg);
                        setTimeout(()=>{
                            location.href = result.url;
                            return false;
                        },1000)

                    }else if(result.code == -1){
                        layer.msg(result.msg);return false;
                    } else{
                        layer.msg(result.msg);
                        setTimeout(()=>{
                            location.href = result.url;
                            return false;
                        },1000)


                    }
                }
            });
            return false;


        }else{
            return false;
        }
        return false;

    });






    });


                        $(function() {
                            $(document).on('change', '#videos', function () {

            // $('#dataLoading').show();
            var files = document.getElementById('videos').files[0];

            var formData = new FormData();
            var obj = $(this);
            formData.append('file', files);
            var url = $(this).attr('data-action');
            $.ajax({
                //请求方式
                type: "POST",
                //请求地址
                url: url,
                data: formData,
                cache: false,  //默认是true，但是一般不做缓存
                processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                //请求成功
                success: function (result) {

                    if (result.msg == 1) {
                        $('.vide').empty();
                        $('#dataLoading').hide();
                        layer.msg('上传成功');
                        $("#video_name").val(result.files_name);
                        // $("type[name='old_filename']").val(result.old_name);
                    } else {
                        obj.val('');
                        $('#dataLoading').hide();
                        layer.msg('文件信息错误,请重新上传');
                        return false;
                    }

                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                    console.log(e.status);
                    console.log(e.responseText);
                }
            });

        });
                            $('#type_div').perfectScrollbar();
                            $("#pic").change(function() {
                                $("#textfield1").val($(this).val());
                            });
                            $('input[type="radio"][name="t_id"]').change(function() {
                                // 标记类型时候修改 修改为ok
                                var t_id = {$class_array.type_id};
                                if (t_id != $(this).val()) {
                                    $('#t_sign').val('ok');
                                } else {
                                    $('#t_sign').val('');
                                }

                                if ($(this).val() == '0') {
                                    $('#t_name').val('');
                                } else {
                                    $('#t_name').val($(this).next('span').html());
                                }
                            });



                            // 类型搜索
                            $(document).off('change',"#gcategory > select").on("change","#gcategory > select", function() {
                                type_scroll($(this));
                            });
                        });
                        var typeScroll = 0;
                        function type_scroll(o) {
                            var id = o.val();
                            if (!$('#type_dt_' + id).is('dt')) {
                                return false;
                            }
                            
                            $('#type_div').scrollTop(-typeScroll);
                            var sp_top = $('#type_dt_' + id).offset().top;
                            var div_top = $('#type_div').offset().top;
                            $('#type_div').scrollTop(sp_top - div_top);
                            typeScroll = sp_top - div_top;
                        }
                        gcategoryInit('gcategory');
</script> 
